<?php

namespace App\Kuafu\Banner\Validate;

use App\Kuafu\Banner\Model\BannerConfigModel;
use Illuminate\Http\Request;
use App\Kuafu\Base\Validate\BaseValidate;

class BannerConfigValidate extends BaseValidate
{
    public static function getBannerById($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    public static function getBannerList($data)
    {
        $rules    = [
            'pageSize' => self::commonRules('pageSize'),
            'pageNum'  => self::commonRules('pageNum'),
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

    /**
     * @param Request $request
     * @return string
     * 横幅添加验证
     */
    public static function addBannerConfig(Request $request)
    {
        $rules    = [
            'name' => [
                'required',
                'max:50',
                function ($attribute, $value, $fail) use ($request) {
                    if (BannerConfigModel::query()->where(['name' => $request->name])->first()) {
                        $fail("该条广告横幅名称已被占用");
                    }
                }
            ],
            'desc' => 'required',
        ];
        $messages = [];

        return self::validateCheck($request->all(), $rules, $messages);
    }

    /**
     * @param Request $request
     * @return string
     * 横幅修改参数验证
     */
    public static function setBannerConfig(Request $request)
    {
        $rules    = [
            'id'   => 'required|integer|min:0',
            'name' => 'required|max:50',
            'desc' => 'required',
        ];
        $messages = [];

        return self::validateCheck($request->all(), $rules, $messages);
    }

    /**
     * @param $data
     * @return string
     * 横幅删除验证
     */
    public static function delBannerConfig($data)
    {
        $rules    = [
            'id' => 'required|integer|min:0',
        ];
        $messages = [];

        return self::validateCheck($data, $rules, $messages);
    }

}
